package com.gy.wx_demo_mg.config;
import javax.sql.DataSource;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.alibaba.druid.pool.DruidDataSource;

/**
 * mybatis配置设置
 * @author liping
 * @create 2017-10-19 下午6:17
 */
@Configuration
@MapperScan("com.gy.wx_demo_mg.dao")
public class MybatisConfig {

    @Autowired
    private DataSourceProperties dataSourceProperties;

    @Bean
    public DataSource dataSource(){
        //return dataSourceProperties.initializeDataSourceBuilder().build();
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setUsername(dataSourceProperties.getUsername());
        druidDataSource.setPassword(dataSourceProperties.getPassword());
        druidDataSource.setUrl(dataSourceProperties.getUrl());
        druidDataSource.setMaxActive(200);
        druidDataSource.setInitialSize(100);
        druidDataSource.setMinIdle(50);
        return druidDataSource;
    }

}
